package org.example.mallchat.dao;

import org.example.mallchat.domain.entity.User;
import org.example.mallchat.mapper.UserMapper;
import org.example.mallchat.service.iservice.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author ZZH
 * @since 2024-12-18
 */
@Service
public class UserDao extends ServiceImpl<UserMapper, User> implements IUserService {

    /**
     * 根据openId获取用户信息
     * @param openId
     * @return
     */
    @Override
    public User getUserByOpenId(String openId) {
        return this.lambdaQuery().eq(User::getOpenId, openId).one();
    }

    /**
     * 根据uid修改用户昵称
     * @param uid
     * @param userName
     */
    @Override
    public void modifyUserNameReduceCardCount(String uid, String userName) {
        this.lambdaUpdate().set(User::getName,userName).eq(User::getId,uid).update();
    }

    /**
     * 根据uid佩戴徽章
     * @param uid
     * @param wearingItemId
     */
    @Override
    public void wearBadge(String uid, Long wearingItemId) {
        this.lambdaUpdate().set(User::getItemId, wearingItemId).eq(User::getId, uid).update();
    }
}
